
package com.eyedog.video.videoad;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewStub;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.eyedog.video.R;
import com.eyedog.video.adv.AdvInstance;
import com.eyedog.video.advui.AdvActivity;
import com.eyedog.video.entity.ADVEntity;
import com.eyedog.video.videodetail.VideoDetailActivity;
import com.eyedog.video.webview.WebFragment;

public class VideoDetailAdActivity extends VideoDetailActivity {

    private final String TAG = "VideoDetailAdActivity";
    // Bundle data;

    ImageView ivAd0, ivAd1;

    // TextView tvTitle;

    ADVEntity advEntity0, advEntity1;

    protected boolean mHasChangedOrientation = false;

    public static Bundle createBundle(String videoUrl, String thumbUrl, String title) {
        Bundle data = new Bundle();
        if (!TextUtils.isEmpty(videoUrl)) {
            data.putString("VIDEO_URL", videoUrl);
            data.putString("THUMB_URL", thumbUrl);
            data.putString("TITLE", title);
        }
        return data;
    }

    @Override
    protected void onContentCreated(ViewStub contentLayout) {
        super.onContentCreated(contentLayout);
        ivAd0 = (ImageView) findViewById(R.id.iv_detail_adv0);
        ivAd1 = (ImageView) findViewById(R.id.iv_detail_adv1);
        if (ivAd0 != null && ivAd1 != null) {
            ivAd0.setOnClickListener(this);
            ivAd1.setOnClickListener(this);
            advEntity0 = AdvInstance.getInstance().getVideoDetailAdv0();
            advEntity1 = AdvInstance.getInstance().getVideoDetailAdv1();
            if (advEntity0 != null) {
                Glide.with(this).load(advEntity0.img).placeholder(R.color.black).into(ivAd0);
            }
            if (advEntity1 != null) {
                Glide.with(this).load(advEntity1.img).placeholder(R.color.black).into(ivAd1);
            }
        }
    }

    @Override
    protected void onFullScreen() {
        super.onFullScreen();
        mHasChangedOrientation = true;
        if (ivAd0 != null) {
            ivAd0.setVisibility(View.GONE);
        }
        if (ivAd1 != null) {
            ivAd1.setVisibility(View.GONE);
        }
    }

    @Override
    protected void onShrinkFullScreen() {
        super.onShrinkFullScreen();
        mHasChangedOrientation = true;
        if (ivAd0 != null) {
            ivAd0.setVisibility(View.VISIBLE);
        }
        if (ivAd1 != null) {
            ivAd1.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.iv_detail_adv0:
                if (advEntity0 != null && !TextUtils.isEmpty(advEntity0.url)) {
                    Uri uri = Uri.parse(advEntity0.url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                }
                break;
            case R.id.iv_detail_adv1:
                if (advEntity1 != null && !TextUtils.isEmpty(advEntity1.url)) {
                    Uri uri = Uri.parse(advEntity1.url);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                }
                break;
        }
    }
}
